package com.neuqsoft.rd.citizen.thirdapp.demo.service;

import com.neuqsoft.rd.citizen.thirdapp.demo.DemoConstant;
import com.neuqsoft.rd.citizen.thirdapp.demo.dto.OrderResultDTO;
import com.neuqsoft.rd.citizen.thirdapp.demo.dto.UserLoginDTO;
import com.neuqsoft.rd.citizen.thirdapp.sdk.OAuthService;
import com.neuqsoft.rd.citizen.thirdapp.sdk.PayService;
import com.neuqsoft.rd.citizen.thirdapp.sdk.dto.NeuqOrderStateRsp;
import com.neuqsoft.rd.citizen.thirdapp.sdk.dto.NeuqTradePayRsp;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @author baidh
 * @date 2020/12/02
 */
@Service
public class Scene3Service {

    @Autowired
    OAuthService oAuthService;

    @Autowired
    private PayService payService;

    public UserLoginDTO oauthToken(String code, String redirectUri) {
        return oAuthService.oauthToken(code, redirectUri);
    }

    public OrderResultDTO onlinePay(String authToken) {
        // 构造订单（省略）

        // 支付下单接口
        final NeuqTradePayRsp rsp = payService.tradePay(authToken, "1", "线上购票", "3000");

        // 构造返回结果
        OrderResultDTO dto = new OrderResultDTO();
        dto.setAppId(DemoConstant.APPID);
        dto.setBizNo(rsp.getBizNo());
        return dto;
    }

    public NeuqOrderStateRsp tradeState(String bizNo) {
        // 查询订单状态
        final NeuqOrderStateRsp rsp = payService.tradeState(bizNo);
        if ("03".equals(rsp.getTradeState())) {
            // 支付成功的订单处理

        }
        return rsp;
    }
}
